/**
 * Created by DELL on 2017/5/9.
 */
var userInfo=common.getLocalData(common.agentSysCacheWord).user;
var $form=$("form");
var $banner=$("#banner");

window.formObject = $form.submit(function() {
    var data = common.formToJson($(this));
    if(!data.banner){
        layer.alert("请上传banner图片");
        return false;
    }
    var sendData={paramKey:"banner",paramValue:data.banner};
    $.post(window.globalHost + common.setSystemConfPath, sendData).success(function(data) {
        layer.alert(data.res.msg);
        if ("0" == data.code) {
            //如果更新成功，重新渲染页面
            window.location.reload();
        }
    });
    return false;
});

$.post(window.globalHost+common.getSystemConfPath,{paramKey:"banner"}).success(function (data) {
    var record;
    if(data.code=="1"){
        record = {
            paramValue:""
        };
    }else if(data.code=="0"){
        record=common.transformData(data);
    }
    $banner.val(record.paramValue);
    var bannerGallery=$("#banner-photos").gallery({
        // readOnly:$.fn.gallery.defaults.readOnly,
        readOnly:false,
        title: "banner信息",
        maxFiles:6,
        url: window.globalHost + common.uploadImagePort,
        paramName: "uploadData",
        fileFolder: {folder: "banner",id:userInfo.id,fileName:"sys_banner_"+new Date().getTime()},
        returnPathName: "filePath",
        filePaths: record.paramValue ? record.paramValue.split(',') : [],
        uploadCallback: function (filePath) {
            var bannerPaths= bannerGallery.getFilePaths();
            $banner.val(bannerPaths.length?bannerPaths.join(","):"");
        },
        deleteCallback: function (filePath) {
            var bannerPaths= bannerGallery.getFilePaths();
            $banner.val(bannerPaths.length?bannerPaths.join(","):"");

        }
    });

});


